<?php
declare(strict_types=1);
namespace Dao;
// hook dao_sys_dict_use.php

use Field\SysDictConst;
use Model\SysDictModel;

class SysDictDao extends SysDictModel
{
	// hook dao_sys_dict_public_start.php

	protected array $add_rule	=	[];
    protected array $edit_rule	=	[];

    protected array $rule	=	[
		/*
		"mobile"=>[
			"max"=>3
			"min"=>3
			"func"=>'isMobile'
			"error"=>false,
			'message'=>'格式有误'
		],
		"username"=>[
			"max"=>3
			"min"=>3
			"func"=>'checkS'
			"error"=>false,
			'message'=>'格式有误'
		],
		*/
	];
	//数据，字段，验证规则
	/*
	function isMobile($data,$field,$val){
	
		return true;
	}
	*/
	
	// hook dao_sys_dict_public_end.php

    public function CacheDict()
    {
        $data = $this->CacheGet('SysDict');
        if(empty($data[0])){
            $dict = $this->select([SysDictConst::Status => 1]);
            $data=[];
            foreach ($dict as $row){
                if(empty($row[SysDictConst::DictKey]) || empty($row[SysDictConst::Content])){
                    continue;
                }
                $data[$row[SysDictConst::DictKey]]=[
                    'DictName'=>$row[SysDictConst::DictName],
                    'Content'=>xn_json_decode($row[SysDictConst::Content])
                ];
            }
            $this->CacheSet('SysDict',$data);
        }
        return $data;
    }

    public function update(array $cond, array $new): bool|int
    {
        $this->CacheDel('SysDict');
        return parent::update($cond, $new); // TODO: Change the autogenerated stub
    }

    public function updateByPk(int|array $pk_arr, array $new): bool|int
    {
        $this->CacheDel('SysDict');
        return parent::updateByPk($pk_arr, $new); // TODO: Change the autogenerated stub
    }

    public function updateByIndex(array $cond_array, array $new): bool|int
    {
        $this->CacheDel('SysDict');
        return parent::updateByIndex($cond_array, $new); // TODO: Change the autogenerated stub
    }

    public function delete(array $cond): bool|int
    {
        $this->CacheDel('SysDict');
        return parent::delete($cond); // TODO: Change the autogenerated stub
    }

    public function deleteByPk(int|array $pk_arr): bool|int
    {
        $this->CacheDel('SysDict');
        return parent::deleteByPk($pk_arr); // TODO: Change the autogenerated stub
    }

    public function deleteByIndex(array $cond_array): bool|int
    {
        $this->CacheDel('SysDict');
        return parent::deleteByIndex($cond_array); // TODO: Change the autogenerated stub
    }

    // hook dao_sys_dict_end.php
}
?>